Commentary - Sample Code (DerbyCommentary)

Commentary - Sample Code (DerbyCommentary)

This sample Commentary plugin returns HTML content. It retrieves the HTML content from a DERBY database, using the target.

The Commentary plugin in this example does the following:

 

The sample code will cover the following:

Setup

This sample code needs the following to run:

About the DERBY SQL database

The DERBY SQL database is created by using create_db.sql which is located in examples\interview-engine\derby-commentary\src.

The 'COMMENT_LOCATION' column contains the ID of the 'target' to match.

The 'COMMENT_CONTENT" column contains the HTML commentary content for the 'target'.

 

Commentary
COMMENT_ID
COMMENT_LOCATION
COMMENT_CONTENT

About the DerbyCommentary plugin

To setup this scenario:

  1. Create the SQL Database using create_db.sql which can be found in examples\interview-engine\derby-commentary\src
  2. Copy the rulebase .zip file (for example, Parents and Children.zip) from examples\rulebases\compiled to the rulebase folder in Web Determinations (for example, <webroot>\WEB-INF\classes\rulebases)
  3. Copy and install the DerbyCommentary.jar file (located in examples\interview-engine\derby-commentary) into Web Determinations; for more information, refer to Create a Plugin
  4. Copy the DERBY libraries to the library folder in Web Determinations (for example, <webroot>\WEB-INF\lib)

  5. Ensure that DERBY is run in network server mode

  6. Run a Web Determinations Interview

How the DerbyCommentary plugin works

Once registered, Web Determinations will call DerbyCommentary.isCommentaryEnabled() when a screen is to be displayed; the DerbyCommentary plugin always returns true.

When a screen is to be displayed, Web Determinations calls DerbyCommentary.hasCommentary() method for the screen itself, to check if commentary information exists for the screen. The same method is also called for each attribute control to be displayed in the screen. DerbyCommentary.hasCommentary() uses the target to query DERBY database and check if commentary data is available for the target screen/attribute.

If DerbyCommentary.hasCommentary() returns true for a target, its label is rendered as a link.

When the user clicks on the label link, Web Determinations calls DerbyCommentary.isCommentaryRedirect() to check if the commentary for the target (the clicked label link) returns URL or HTML content; the DerbyCommentary plugin always returns false, since it can only provide commentary in HTML content. 

Web Determinations then calls DerbyCommentary.getCommentaryContent() to get the HTML commentary content for the target. DerbyCommentary queries the DERBY database and retrieves the commentary for the target. As mentioned before, the DERBY database has stored the commentary in pure HTML format, so DerbyCommentary does not need to process the data from DERBY database into HTML. DerbyCommentary encapsulates the HTML string in a TypedInputStream, and returns it to Web Determinations for display. A sequence similar to the above, can be found in Commentary Plugin

Source Code

To view the source code for the DerbyCommentary sample, refer to examples\interview-engine\derby-commentary in the Java runtime zip file.